package com.school.HomeWork.Factory.abstractFactory;

// 抽象工厂接口
interface AbstractFactory {
    AbstractProductA createProductA();
    AbstractProductB createProductB();
}

// 具体工厂1
class ConcreteFactory1 implements AbstractFactory {
    public AbstractProductA createProductA() {
        return new ProductA1();
    }
    public AbstractProductB createProductB() {
        return new ProductB1();
    }
}

// 具体工厂2
class ConcreteFactory2 implements AbstractFactory {
    public AbstractProductA createProductA() {
        return new ProductA2();
    }
    public AbstractProductB createProductB() {
        return new ProductB2();
    }
}

// 抽象产品A
interface AbstractProductA {
    void usefulFunctionA();
}

// 抽象产品B
interface AbstractProductB {
    void usefulFunctionB();
}

// 具体产品A1
class ProductA1 implements AbstractProductA {
    public void usefulFunctionA() {
        System.out.println("ProductA1功能实现");
    }
}

// 具体产品A2
class ProductA2 implements AbstractProductA {
    public void usefulFunctionA() {
        System.out.println("ProductA2功能实现");
    }
}

// 具体产品B1
class ProductB1 implements AbstractProductB {
    public void usefulFunctionB() {
        System.out.println("ProductB1功能实现");
    }
}

// 具体产品B2
class ProductB2 implements AbstractProductB {
    public void usefulFunctionB() {
        System.out.println("ProductB2功能实现");
    }
}

// 客户端代码
public class Client {
    public static void main(String[] args) {
        AbstractFactory factory;
        factory = new ConcreteFactory1();
        AbstractProductA productA = factory.createProductA();
        AbstractProductB productB = factory.createProductB();

        productA.usefulFunctionA();
        productB.usefulFunctionB();

        factory = new ConcreteFactory2();
        productA = factory.createProductA();
        productB = factory.createProductB();

        productA.usefulFunctionA();
        productB.usefulFunctionB();
    }
}
